package fichier;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

public class main {
	public static boolean testUpdate=true;
	public static JComboBox boxBox = new JComboBox();
	public static DefaultComboBoxModel model = new DefaultComboBoxModel();

	public static void main (String[] args){
		@SuppressWarnings("unused")
		SelectData test = new SelectData();
		main.updateModel();
		@SuppressWarnings("unused")
		Connexion c = new Connexion();
	}
	
	public static void updateModel(){
		main.model = new DefaultComboBoxModel();
		SelectData.REQUETE  = "SELECT id_box, nom_box FROM box ORDER BY id_box";
		ResultSet lignesfr = SelectData.startSelect();
		int nbligne=0;

		try{
			while(lignesfr.next()){
				nbligne++;
			}

		}
		catch(SQLException e2){
			System.out.println("error"); 
		}

		String[] boxboxtab = new  String[nbligne+1];

		SelectData.REQUETE  = "SELECT id_box, nom_box FROM box ORDER BY id_box";
		ResultSet resultat = SelectData.startSelect();
		int i=1;
		boxboxtab[0] = "";

		try{
			while(resultat.next()){
				boxboxtab [i] = resultat.getString("nom_box");
				i++;
			}

		}
		catch(SQLException e3){
			System.out.println(""); 
		}
		for (i=1; i<=nbligne; i++){
			main.model.addElement(boxboxtab[i]);
		}
		main.boxBox.setModel(main.model);
	}
}
